package com.jillchen.grpc.server.services;
/*

import com.google.protobuf.ByteString;
import com.jillchen.grpc.libs.DocsConvertGrpc;
import com.jillchen.grpc.libs.Convert;
import com.jillchen.grpc.libs.GreeterOuterClass;
import com.jillchen.grpc.server.convertprovidors.ConvertDocs;
import com.jillchen.grpc.server.convertprovidors.ConvertPdf;
import com.jillchen.grpc.server.utils.AbsConverter;
import io.grpc.stub.StreamObserver;
import lombok.extern.slf4j.Slf4j;
import net.devh.springboot.autoconfigure.grpc.server.GrpcService;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileOutputStream;
import java.io.InputStream;

@Slf4j
@GrpcService(Convert.class)
public class ConvertStreamService extends DocsConvertGrpc.DocsConvertImplBase {
    @Override
    public void convert(Convert.RequestFileStream request,
                        StreamObserver<Convert.ResponseFileStreamReply> responseObserver) {
       ByteString bys=request.getArrs();
        byte[] btyeArr=bys.toByteArray();


        InputStream inputStream = new ByteArrayInputStream(btyeArr);
        try {
          //  Document doc = new Document(inputStream);
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
           // doc.save(outStream, SaveFormat.PDF);//保存到流
            AbsConverter converter=new ConvertDocs();
            converter.Convert(inputStream,"abc.docx",outStream,"123.pdf");
            ByteString byteString = ByteString.copyFrom(outStream.toByteArray());//stream2ByteString
            final Convert.ResponseFileStreamReply.Builder replyBuilder = Convert.ResponseFileStreamReply.newBuilder().setArrs(byteString);
            responseObserver.onNext(replyBuilder.build());
            responseObserver.onCompleted();

        } catch (Exception e) {

        }
    }
}*/
